﻿/**  版本信息模板在安装目录下，可自行修改。
* SaleInfo.cs
*
* 功 能： N/A
* 类 名： SaleInfo
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013-11-13 9:40:43   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：从零至一（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Collections.Generic;
using ZhiKeDuoServer.Model;
namespace ZhiKeDuoServer.BLL
{
    /// <summary>
    /// SaleInfo
    /// </summary>
    public partial class SaleInfo
    {
        private readonly DAL.SaleInfoService dal = new DAL.SaleInfoService();
        public SaleInfo()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string Pid)
        {
            return dal.Exists(Pid);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(ZhiKeDuoServer.Model.SaleInfo model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ZhiKeDuoServer.Model.SaleInfo model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string Pid)
        {

            return dal.Delete(Pid);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Pidlist)
        {
            return dal.DeleteList(Pidlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZhiKeDuoServer.Model.SaleInfo GetModel(string Pid)
        {

            return dal.GetModel(Pid);
        }



        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ZhiKeDuoServer.Model.SaleInfo> GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
       

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ZhiKeDuoServer.Model.SaleInfo> GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public List<ZhiKeDuoServer.Model.SaleInfo> GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod

        /// <summary>
        /// 获得日报表
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public DataTable GetDayReport(string where)
        {
            string sql = "SELECT sum(Counts) as Counts1,sum(Price) as Price1,Format(IDate,\"yyyy-mm-dd\")as IDate1 FROM SaleInfo where 1=1 " + where + " group by Format(IDate,\"yyyy-mm-dd\")";
            return dal.GetSql(sql);

        }

        /// <summary>
        /// 得到一个最新一个对象
        /// </summary>
        public ZhiKeDuoServer.Model.SaleInfo GetPreModel(string Oper)
        {
            return dal.GetPreModel(Oper);
        }

        public DataSet getToday(string userid)
        {
            DataSet ds = new DataSet();
            string strSql = "SELECT pid, priceSum, count(0) AS c, VipCode FROM SaleInfo where Oper='" + userid + "' and Idate>'" + DateTime.Now.Date + "' GROUP BY pid, priceSum, VipCode";
            return dal.GetDataSql(strSql);
         
        }
        public DataTable getDayRePort(DateTime dt1, DateTime dt2)
        {

            return dal.GetSql("SELECT sum(Counts) as Counts1 ,sum(Price) as Price1,sum(SumGain1) as Gain,IdateT AS Idate1 FROM v_Gain where 1=1 and Idate>'" + dt1 + "' and Idate<='" + dt2 + "' group by IdateT");
        }
        public DataTable getMonthRePort(string strYear)
        {
            DateTime dt1 = Convert.ToDateTime(strYear + "-01-01 00:00:00");
            DateTime dt2 = Convert.ToDateTime(strYear + "-12-31 23:59:59");
            DataTable dt = new DataTable();
            dt =  dal.GetSql("SELECT sum(Counts) as Counts1 ,sum(Price) as Price1,sum(SumGain1) as Gain,IdateM AS Idate1 FROM v_Gain where 1=1 and Idate>'" + dt1 + "' and Idate<='" + dt2 + "' group by IdateM");

            return dt;
        }
        public DataSet GetListPage(string strWhere, int pageSize, int page)
        {
            DataSet ds = new DataSet();
            string strSql = "";
            if (strWhere != "")
            {
                strSql = "select  * from v_SaleInfoDetail where " + strWhere + " order by id limit "+(pageSize * (page - 1)) + "," + pageSize;
            }
            else
            {
                strSql = "select * from v_SaleInfoDetail  order by id limit " + (pageSize * (page - 1)) + "," + pageSize;

            }
            ds =   dal.GetDataSql(strSql);
            return ds;
        }
        public DataTable Jiaoban(int banci,int shop,string opt) {
           
            return dal.Jiaoban(banci ,shop ,opt);
        }


        #endregion  ExtensionMethod
    }
}

